/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package skytestarmor;

import java.util.ArrayList;
import java.util.Collection;
import ru.jSkyRoom.finder.FinderByEdidFacade;
import ru.jSkyRoom.interfaces.JSkyMod;
import ru.jSkyRoom.interfaces.major.Armor;
import ru.jSkyRoom.interfaces.major.Keyword;
import skyproc.ARMO;
import skyproc.FormID;
import skyproc.Mod;

/**
 *
 * @author alx
 */
public class TypeArmor {

    private String enchName = ""; //Alchemy
    private String nameLeveledItemGroup = ""; //Necklace
    private boolean itIsArmor = false;
    private boolean itIsRobes = false;
    private ArrayList<String> arNameHiehGroupOfLeveledItems = new ArrayList<>();
    private String lvl;
    private String personItemName;

    public TypeArmor(Armor armor, JSkyMod patc, Collection<String> listOfDragonDaedric) {
//        lvl = getLevelOfArmor(armor);
        full_itIsArmor_itIsRobes_nameLeveledItemGroup(armor, patc);
        full_lvl_enchName(armor);

        String armorgetEDID = armor.getEDID();
        String nameOfHiehGroup;
        personItemName = armorgetEDID.substring(7, armorgetEDID.lastIndexOf("_"));//Valkyrie_Gloves
        String nameOfSet = personItemName.substring(0, personItemName.lastIndexOf("_"));//Valkyrie
        if (itIsArmor) {
            //str = armor.getEDID(); //LBench_Valkyrie_Gloves_Alchemy04
            /*
             LBench_Valkyrie_Gloves_Alchemy04 - item
             LBenchArmorS_Valkyrie_Gloves_04
             LItemEnchArmorLightGauntlets_LB_z04  <----
             LItemEnchArmorLightGauntlets_LB_KR
             LItemEnchArmorLightGauntlets
             */
            nameOfHiehGroup = "LItemEnchArmor" + nameLeveledItemGroup + "_LB_z" + lvl; //LItemEnchArmorLightBoots_LB_z01
//String nameOfHiehGroup = "LItemEnchArmor" + nameLeveledItemGroup + "_z" + lvl; //LItemEnchArmorLightBoots_LB_z01

            arNameHiehGroupOfLeveledItems.add(nameOfHiehGroup);
            if (!listOfDragonDaedric.contains(nameOfSet)) {
                nameOfHiehGroup = "LItemEnchArmor" + nameLeveledItemGroup + "NoDragon_LB_z" + lvl; //LItemEnchArmorLightBootsNoDragon_LB_z01
                arNameHiehGroupOfLeveledItems.add(nameOfHiehGroup);
            }
        } else {
            if (itIsRobes) {
                /*
                 LBench_Frostbite_Cuirass_AlterationR03 - item
                 LBench_RobesAlteration_03 <----
                 LItemRobesAlteration_LB_KR
                 LItemRobesAlteration
                 * */


                //str = armor.getEDID(); //LBench_Frostbite_Cuirass_AlterationR03
                nameOfHiehGroup = "LBench_Robes" + this.enchName + "_" + lvl; //LBench_RobesAlteration_03
                arNameHiehGroupOfLeveledItems.add(nameOfHiehGroup);
                nameOfHiehGroup = "LBenchArmorS_" + personItemName + "_" + lvl; //LBenchArmorS_Valkyrie_Gloves_04
                //nameOfHiehGroup = "LBenchRobeS_" + personItemName + "_" + lvl; //LBenchArmorS_Valkyrie_Gloves_04
                arNameHiehGroupOfLeveledItems.add(nameOfHiehGroup);
            } else {
                /*LBench_Chaos_Amulet_Block03 - item
                 LBench_NecklaceBlock_03  <----            LBench_Chaos_Amulet_03 <----
                 LItemEnchNecklaceBlock_LB_KR
                 LItemEnchNecklaceBlock
                 */
                nameOfHiehGroup = "LBench_" + this.nameLeveledItemGroup + this.enchName + "_" + lvl; //LBench_RobesAlteration_03
                arNameHiehGroupOfLeveledItems.add(nameOfHiehGroup);
               nameOfHiehGroup = "LBench_" + personItemName + "_" + lvl; //LBench_RobesAlteration_03
                arNameHiehGroupOfLeveledItems.add(nameOfHiehGroup);
            }
        }

    }

    private String getLevelOfArmor(Armor armor) {
        String editName = armor.getEDID();
        if (editName.contains("Muffle")) {
            return "03";
        } else {
            return editName.substring(editName.length() - 2);
        }

    }

    private void full_lvl_enchName(Armor armor) {
        String editName = armor.getEDID();
        if (editName.contains("Muffle")) {
            this.lvl = "03";
            this.enchName = "Muffle";
        } else {
            this.lvl = editName.substring(editName.length() - 2);
            if (this.itIsRobes) {
                this.enchName = editName.substring(editName.lastIndexOf("_") + 1, editName.length() - 3);
            } else {
                this.enchName = editName.substring(editName.lastIndexOf("_") + 1, editName.length() - 2);
            }
        }

    }

    private void full_itIsArmor_itIsRobes_nameLeveledItemGroup(Armor armor, JSkyMod patc) {
        Keyword ArmorBootsFID = getFinder().findKeyword("ArmorBoots");
        Keyword ArmorCuirassFID = getFinder().findKeyword("ArmorCuirass");
        Keyword ArmorGauntletsFID = getFinder().findKeyword("ArmorGauntlets");
        Keyword ArmorHelmetFID = getFinder().findKeyword("ArmorHelmet");
        Keyword ArmorShieldFID = getFinder().findKeyword("ArmorShield");
        Keyword ArmorHeavyFID = getFinder().findKeyword("ArmorHeavy");
        Keyword ArmorLightFID = getFinder().findKeyword("ArmorLight");

        Keyword ClothingNecklaceFID = getFinder().findKeyword("ClothingNecklace");
        Keyword ClothingRingFID = getFinder().findKeyword("ClothingRing");
        Keyword ClothingFeetFID = getFinder().findKeyword("ClothingFeet");
        Keyword ClothingBodyFID = getFinder().findKeyword("ClothingBody");
        Keyword ClothingHandsFID = getFinder().findKeyword("ClothingHands");
        Keyword ClothingHeadFID = getFinder().findKeyword("ClothingHead");
        Keyword ClothingCircletFID = getFinder().findKeyword("ClothingCirclet");

        Collection<Keyword> keywordSet = armor.getKeywords();
        String tip = "";
        if (keywordSet.contains(ArmorBootsFID)) {
            tip = "Boots";
        } else if (keywordSet.contains(ArmorCuirassFID)) {
            tip = "Cuirass";
        } else if (keywordSet.contains(ArmorGauntletsFID)) {
            //tip = "Gloves";
            tip = "Gauntlets";
        } else if (keywordSet.contains(ArmorHelmetFID)) {
            tip = "Helmet";
        } else if (keywordSet.contains(ArmorShieldFID)) {
            tip = "Shield";
        }
        if (!tip.isEmpty()) {
            itIsArmor = true;
            if (keywordSet.contains(ArmorLightFID)) {
                nameLeveledItemGroup = "Light" + tip;
            } else {
                nameLeveledItemGroup = "Heavy" + tip;
            }
        } else {
            itIsArmor = false;
            if (keywordSet.contains(ClothingNecklaceFID)) {
                nameLeveledItemGroup = "Necklace";
            } else if (keywordSet.contains(ClothingRingFID)) {
                nameLeveledItemGroup = "Ring";
            } else if (keywordSet.contains(ClothingCircletFID)) {
                nameLeveledItemGroup = "Circlet";
            } else if (keywordSet.contains(ClothingFeetFID)) {
                nameLeveledItemGroup = "Robes";
                itIsRobes = true;
            } else if (keywordSet.contains(ClothingBodyFID)) {
                nameLeveledItemGroup = "Robes";
                itIsRobes = true;
            } else if (keywordSet.contains(ClothingHandsFID)) {
                nameLeveledItemGroup = "Robes";
                itIsRobes = true;
            } else if (keywordSet.contains(ClothingHeadFID)) {
                nameLeveledItemGroup = "Robes";
                itIsRobes = true;
            }
        }
    }

    //**************************************************************************************************
    //Геттеры
    public String getNameLeveledItemGroup() {
        return nameLeveledItemGroup;
    }

    public boolean isArmor() {
        return itIsArmor;
    }

    public ArrayList<String> getArNameHiehGroupOfLeveledItems() {
        return arNameHiehGroupOfLeveledItems;
    }

    public String getLvl() {
        return lvl;
    }

    public String getEnchName() {
        return enchName;
    }

    public boolean isRobes() {
        return itIsRobes;
    }

    public String getPersonItemName() {
        return personItemName;
    }

    protected final FinderByEdidFacade getFinder() {
        return FinderByEdidFacade.create();
    }
}
